package com.syni.mdd.sjb.common.datatreaure.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.entity.*;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.mapper.DxshAppServiceOrderMapper;
import com.syni.mdd.sjb.common.component.mybatis.dxshapp.mapper.DxshAppServicesMapper;
import com.syni.mdd.sjb.common.component.utils.common.utils.*;
import com.syni.mdd.sjb.common.component.utils.feign.service.mdd.commonuser.UserRestService;
import com.syni.mdd.sjb.common.datatreaure.service.*;
import com.syni.mdd.sjb.common.datatreaure.constants.Constants;
import com.syni.mdd.sjb.common.datatreaure.constants.ResultMsg;
import com.syni.mdd.sjb.common.datatreaure.entity.bo.services.DxshAppServiceFatherBo;
import com.syni.mdd.sjb.common.datatreaure.entity.bo.userChannel.MinAppServiceBo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.service.*;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rp.successExample.ExampleRpVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.services.GetServicesByIdRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.services.GetServicesBySonIdRqVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.services.MyServicesVo;
import com.syni.mdd.sjb.common.datatreaure.entity.vo.rq.services.SearchRqVo;
import com.syni.mdd.sjb.common.datatreaure.mybatis.MybatisUtils;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

/**
 * <p>
 * 电享生活APP 服务表 服务实现类
 * </p>
 *
 * @author lcc
 * @since 2020-04-26
 */
@Service
@Log4j2
public class DxshAppServicesServiceImpl extends ServiceImpl<DxshAppServicesMapper, DxshAppServices> implements DxshAppServicesService {

    @Autowired
    DxshAppServicesMapper dxshAppServicesMapper;

    @Autowired
    DxshAppServicesService dxshAppServicesService;

    @Autowired
    DxshAppServiceSonService dxshAppServiceSonService;

    @Autowired
    DxshAppServiceFatherService dxshAppServiceFatherService;

    @Autowired
    DxshAppBannerService dxshAppBannerService;

    @Autowired
    DxshAppSuccessExampleService dxshAppSuccessExampleService;

    @Autowired
    DxshAppServiceOrderMapper dxshAppServiceOrderMapper;

    @Autowired
    DankMerchantsDefBusinessService dankMerchantsDefBusinessService;

    @Autowired
    DxshAppUserChannelService dxshAppUserChannelService;

    @Autowired
    UserRestService userRestService;

    @Override
    public Map<String, Object> getServicesBySonId(GetServicesBySonIdRqVo getServicesBySonIdRqVo) {
        Integer pageSize = getServicesBySonIdRqVo.getPageSize();
        Integer pageNum = getServicesBySonIdRqVo.getPageNum();
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc(DxshAppServices.UPDATE_TIME);
        queryWrapper.eq(DxshAppServices.SON_ID,getServicesBySonIdRqVo.getSonId());
        queryWrapper.eq(DxshAppServices.IS_DELETE, Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.eq(DxshAppServices.IS_OFF,Constants.COMMON_FLAG_FALSE_INT);
        Page<DxshAppServices> page = new Page<>(pageNum,pageSize);
        IPage<DxshAppServices> dxshAppServicesIPage = dxshAppServicesMapper.selectPage(page,queryWrapper);
        Map<String,Object> userData = MybatisUtils.UserData(dxshAppServicesIPage);

        List<DxshAppServices> dxshAppServicesList  = dxshAppServicesIPage.getRecords();
        List<GetServicesBySonIdRpVo> getServicesBySonIdRpVoList = BeanUtils.copyList(dxshAppServicesList,GetServicesBySonIdRpVo.class);
        return ResultMapHelper.success(getServicesBySonIdRpVoList,userData,ResultMsg.MSG_GET_SUCCESS);
    }

    @Override
    public Map<String, Object> getServicesById(GetServicesByIdRqVo getServicesByIdRqVo) {
        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.eq(DxshAppServices.IS_OFF,Constants.COMMON_FLAG_FALSE_INT);
//        queryWrapper.eq(DxshAppServices.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.eq(DxshAppServices.ID,getServicesByIdRqVo.getServiceId());
        DxshAppServices dxshAppServices = this.getOne(queryWrapper);
        if(dxshAppServices == null){
            return ResultMapHelper.failure("无该服务记录");
        }
        //设置服务浏览数加一并保存
        dxshAppServices.setViewNum(dxshAppServices.getViewNum()+1);
        dxshAppServicesService.saveOrUpdate(dxshAppServices);

        //查看该服务是否有被购买
        QueryWrapper orderWrapper = new QueryWrapper();
        queryWrapper.eq(DxshAppServiceOrder.SERVICE_ID,getServicesByIdRqVo.getServiceId());
        queryWrapper.eq(DxshAppServiceOrder.BMS_USER_ID,getServicesByIdRqVo.getUserId());
        queryWrapper.eq(DxshAppServiceOrder.ORDER_TYPE,Constants.SERVICE_ORDER_SET);
        queryWrapper.eq(DxshAppServiceOrder.STATUS,Constants.COMMON_FLAG_TRUE_INT);
        queryWrapper.eq(DxshAppServiceOrder.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        List<DxshAppServiceOrder> orderList = dxshAppServiceOrderMapper.selectList(orderWrapper);

        ServicesRpVo servicesRpVo = BeanUtils.copyProperties(dxshAppServices,ServicesRpVo.class);
        if(StringUtils.checkAnyNotNull(dxshAppServices.getBanner())){
            JSONArray jsonArray = JSON.parseArray(dxshAppServices.getBanner());
            servicesRpVo.setBanner(jsonArray);
        }
        if(orderList.size()>0){
            servicesRpVo.setIsBuy(Constants.COMMON_FLAG_TRUE_INT);
        }else{
            servicesRpVo.setIsBuy(Constants.COMMON_FLAG_FALSE_INT);
        }
        return ResultMapHelper.success(servicesRpVo,ResultMsg.MSG_GET_SUCCESS);
    }

    @Override
    public Map<String, Object> data() {
        int serviceCaseSize = 5;//服务案例数量

        //轮播
        List<BannerRpVo> bannerRpVoList = dxshAppBannerService.bannerList(dxshAppBannerService.type);

        //服务案例
        List<ExampleRpVo> exampleRpVoList = dxshAppSuccessExampleService.serviceCase(1,serviceCaseSize);
        //服务内容
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(DxshAppServiceFather.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        List<DxshAppServiceFather> dxshAppServiceFatherList = dxshAppServiceFatherService.list(queryWrapper);
        List<DxshAppServiceFatherBo> dxshAppServiceFatherBoList = BeanUtils.copyList(dxshAppServiceFatherList,DxshAppServiceFatherBo.class);
        List<DataRpVo> dataRpVoList = BeanUtils.copyList(dxshAppServiceFatherBoList, DataRpVo.class);
        for(DataRpVo item:dataRpVoList){
            queryWrapper.clear();
            queryWrapper.eq(DxshAppServiceSon.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
            queryWrapper.eq(DxshAppServiceSon.FATHER_ID,item.getId());
            queryWrapper.select(DxshAppServiceSon.ID);
            List<DxshAppServiceSon> sons = dxshAppServiceSonService.list(queryWrapper);
            if(sons.size() > 0){
                Set<Integer> sonIds = sons.stream().map(DxshAppServiceSon::getId).collect(Collectors.toSet());
                queryWrapper.clear();
                queryWrapper.eq(DxshAppServices.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
                queryWrapper.eq(DxshAppServices.IS_OFF,Constants.COMMON_FLAG_FALSE_INT);
                queryWrapper.in(DxshAppServices.SON_ID,sonIds);
                queryWrapper.orderByDesc(DxshAppServices.UPDATE_TIME);
                Page<DxshAppServices> page = new Page<>(pageNum,pageSize);
                IPage<DxshAppServices> dxshAppServicesIPage = dxshAppServicesMapper.selectPage(page,queryWrapper);
                List<DxshAppServices> dxshAppServicesList = dxshAppServicesIPage.getRecords();
                List<DataRpVo.DxshAppServicesIndex> dxshAppServicesIndexList = BeanUtils.copyList(dxshAppServicesList,DataRpVo.DxshAppServicesIndex.class);
                item.setData(dxshAppServicesIndexList);
            }

        }
        //服务分类
        List<FatherTagRpVo> fatherTagRpVoList = BeanUtils.copyList(dxshAppServiceFatherList,FatherTagRpVo.class);


        Map<String,Object> map = new HashMap<>();
        map.put("banner",bannerRpVoList);
        map.put("class",fatherTagRpVoList);
        map.put("serviceCase",exampleRpVoList);
        map.put("serviceData",dataRpVoList);
        return ResultMapHelper.success(map,ResultMsg.MSG_GET_SUCCESS);
    }

    @Override
    public Map<String, Object> search(SearchRqVo searchRqVo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(DxshAppServices.TITLE,searchRqVo.getSearchName());
        queryWrapper.eq(DxshAppServices.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.eq(DxshAppServices.IS_OFF,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.orderByDesc(DxshAppServices.UPDATE_TIME);
        List<DxshAppServices> dxshAppServicesList = list(queryWrapper);

        queryWrapper.clear();
        queryWrapper.like(DxshAppSuccessExample.TITLE,searchRqVo.getSearchName());
        queryWrapper.eq(DxshAppSuccessExample.IS_OFF,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.orderByDesc(DxshAppSuccessExample.NEW_TIME);
        List<DxshAppSuccessExample> dxshAppSuccessExampleList = dxshAppSuccessExampleService.list(queryWrapper);

        List<ServicesRpVo> servicesRpVos = BeanUtils.copyList(dxshAppServicesList,ServicesRpVo.class);
        List<ExampleRpVo> exampleRpVos = BeanUtils.copyList(dxshAppSuccessExampleList,ExampleRpVo.class);

        List list = new ArrayList();
        list.addAll(servicesRpVos);
        list.addAll(exampleRpVos);

        List newList = PageUtils.startPage(list,searchRqVo.getPageNum(),searchRqVo.getPageSize());
        Map<String,Object> userData = userData(list,searchRqVo.getPageNum(),searchRqVo.getPageSize());
        return ResultMapHelper.success(newList,userData,ResultMsg.MSG_GET_SUCCESS);
    }

    @Override
    public Map<String, Object> myServices(MyServicesVo myServicesVo) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(DxshAppServiceOrder.BMS_USER_ID,myServicesVo.getUserId());
        queryWrapper.eq(DxshAppServiceOrder.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.eq(DxshAppServiceOrder.STATUS, DxshAppServiceOrderService.PAY_STATUS);
        queryWrapper.orderByDesc(DxshAppServiceOrder.PAY_TIME);
        Page<DxshAppServiceOrder> page = new Page<>(myServicesVo.getPageNum(),myServicesVo.getPageSize());

        IPage<DxshAppServiceOrder> dxshAppServiceOrderIPage = dxshAppServiceOrderMapper.selectPage(page,queryWrapper);
        Map<String,Object> userData = MybatisUtils.UserData(dxshAppServiceOrderIPage);
        List<DxshAppServiceOrder> dxshAppServiceOrderList = dxshAppServiceOrderIPage.getRecords();
        List<MyServicesRpVo> ServicesRpVoList = BeanUtils.copyList(dxshAppServiceOrderList,MyServicesRpVo.class);
        //过滤掉短信服务
        List<MyServicesRpVo> myServicesRpVoList = ServicesRpVoList.stream().filter(s->s.getOrderType()!= DxshAppServiceOrderService.smsType).collect(Collectors.toList());
        myServicesRpVoList.stream().forEach(v->{
            queryWrapper.clear();
            switch (v.getOrderType()){
                case DxshAppServiceOrderService.addedType :
                    queryWrapper.eq(DxshAppServices.ID,v.getServiceId());
                    DxshAppServices dxshAppServices = dxshAppServicesService.getOne(queryWrapper);
                    if(dxshAppServices != null){
                        MyServicesRpVo.Service service = BeanUtils.copyProperties(dxshAppServices,MyServicesRpVo.Service.class);
                        v.setService(service);
                    }
                    break;
                default:break;
            }
        });
        return ResultMapHelper.success(myServicesRpVoList,userData,ResultMsg.MSG_GET_SUCCESS);
    }

    @Override
    public Map<String, Object> getMyServicesList(MyServicesVo myServicesVo) {
        RequestHeaderData requestHeaderData = new RequestHeaderData();
        List<GetMyServicesRpVo> getMyServicesRpVoList = new ArrayList<>();
        Map<String,Object> userData = new HashMap<>();
        userData.put("pageNum",myServicesVo.getPageNum());
        userData.put("pageSize",myServicesVo.getPageSize());
        userData.put("count",Constants.COMMON_FLAG_FALSE_INT);
        userData.put("serviceType",myServicesVo.getServiceType());
        if(myServicesVo.getServiceType() == Constants.MY_SERVICE_TYPE_2){
            //查看是否选择了店铺
            DxshAppUserChannel dxshAppUserChannel = null;
            Integer buisinessId = dankMerchantsDefBusinessService.getChooseBusinessId(myServicesVo.getUserId());
            if(buisinessId != null){
                dxshAppUserChannel = dxshAppUserChannelService.getDxshChannelByBusinessIdAndChannel(buisinessId, DxshAppUserChannelService.CHANNEL_MINAPP);
            }else {
                List<DxshAppUserChannel> dxshAppUserChannels  = dxshAppUserChannelService.getDxshChannelByUserIdAndChannel(myServicesVo.getUserId(), DxshAppUserChannelService.CHANNEL_MINAPP);
                if(CollectionUtils.isNotEmpty(dxshAppUserChannels)){
                    dxshAppUserChannel = dxshAppUserChannels.get(0);
                }
            }
            if(dxshAppUserChannel != null && StringUtils.isNotBlank(dxshAppUserChannel.getStoreId())){
                String storeId = dxshAppUserChannel.getStoreId();
                Map<String,Object> resultMap = getRecordList(myServicesVo.getUserId(),storeId);
//                String result = "{\n" +
//                        "    \"status\": \"00\",\n" +
//                        "    \"data\": [\n" +
//                        "        {\n" +
//                        "            \"recordType\": \"1\",\n" +
//                        "            \"recordCreateTime\": \"2020-11-18T13:22:23\",\n" +
//                        "            \"count\": 2,\n" +
//                        "            \"orderNo\": \"2020111813221601800046399604\",\n" +
//                        "            \"payType\": null,\n" +
//                        "            \"levelId\": 2,\n" +
//                        "            \"levelName\": \"尊享版\",\n" +
//                        "            \"price\": 8888.00,\n" +
//                        "            \"discountPrice\": 0.01,\n" +
//                        "            \"indate\": 365,\n" +
//                        "            \"levelStatus\": 1,\n" +
//                        "            \"discountExpireDate\": \"2021-11-01T10:08:03\",\n" +
//                        "            \"levelWeight\": 1,\n" +
//                        "            \"packageId\": 1,\n" +
//                        "            \"title\": \"小程序平台服务包\",\n" +
//                        "            \"subTitle\": null,\n" +
//                        "            \"packagePreviewImgUrl\": \"https://\",\n" +
//                        "            \"intro\": null,\n" +
//                        "            \"richText\": null,\n" +
//                        "            \"packageStatus\": 1,\n" +
//                        "            \"serviceType\": 0\n" +
//                        "        },\n" +
//                        "        {\n" +
//                        "            \"recordType\": \"2\",\n" +
//                        "            \"recordCreateTime\": \"2020-11-18T13:22:06\",\n" +
//                        "            \"count\": 2,\n" +
//                        "            \"orderNo\": \"2020111813220556200071468748\",\n" +
//                        "            \"payType\": null,\n" +
//                        "            \"levelId\": 2,\n" +
//                        "            \"levelName\": \"尊享版\",\n" +
//                        "            \"price\": 8888.00,\n" +
//                        "            \"discountPrice\": 0.01,\n" +
//                        "            \"indate\": 365,\n" +
//                        "            \"levelStatus\": 1,\n" +
//                        "            \"discountExpireDate\": \"2021-11-01T10:08:03\",\n" +
//                        "            \"levelWeight\": 1,\n" +
//                        "            \"packageId\": 1,\n" +
//                        "            \"title\": \"小程序平台服务包\",\n" +
//                        "            \"subTitle\": null,\n" +
//                        "            \"packagePreviewImgUrl\": \"https://\",\n" +
//                        "            \"intro\": null,\n" +
//                        "            \"richText\": null,\n" +
//                        "            \"packageStatus\": 1,\n" +
//                        "            \"serviceType\": 0\n" +
//                        "        }\n" +
//                        "    ],\n" +
//                        "    \"msg\": \"执行成功\",\n" +
//                        "    \"success\": true\n" +
//                        "}";
//                Map<String,Object> resultMap = JSON.parseObject(result);
                Date nowTime = new Date();
                if(ResultMapHelper.isSuccess(resultMap)){
                    List<MinAppServiceBo> minAppServiceBos = JSON.parseArray(JSON.toJSONString(resultMap.get("data")),MinAppServiceBo.class);
                    if(CollectionUtils.isNotEmpty(minAppServiceBos)){
                        String minAppIndex = dxshAppUserChannelService.getMinAppIndexUrl();
                        for(MinAppServiceBo minAppServiceBo : minAppServiceBos){
                            if(minAppServiceBo.getRecordType() == Constants.PAY_STATUS_EXPIRE
                                    || minAppServiceBo.getRecordType() == Constants.PAY_NO_PAY){
                                continue;
                            }
                            GetMyServicesRpVo getMyServicesRpVo = new GetMyServicesRpVo();
                            getMyServicesRpVo.setUrl(String.format("%s?userToken=%s&storeId=%s&jumpTo=buyService",minAppIndex,requestHeaderData.getString("token"),dxshAppUserChannel.getStoreId()));
                            if(dxshAppUserChannel.getMinAppStatus() != Constants.MINAPP_FRONT_STATUS_RELEASE_SUCCESS) {
                                getMyServicesRpVo.setPayStatus(Constants.PAY_STATUS_NO_START);
                            }
                            getMyServicesRpVo.setStoreId(storeId);
                            getMyServicesRpVo.setTypeName(minAppServiceBo.getTypeName());
                            getMyServicesRpVo.setTitle(minAppServiceBo.getTitle());
                            getMyServicesRpVo.setTotalPrice(minAppServiceBo.getPayAmount());
                            getMyServicesRpVo.setNewTime(DateTimeUtils.
                                    converDateToLocalDateTime(DateTimeUtils.converStringToDate(minAppServiceBo.getRecordCreateTime(),DateTimeUtils.DATE_PATTERN_TIMESTAMP)));
                            getMyServicesRpVo.setPayTime(getMyServicesRpVo.getNewTime());
                            try {
                                Date serviceEnd = DateTimeUtils.addDay(DateTimeUtils.converLocalDateTimeToDate(getMyServicesRpVo.getNewTime()),minAppServiceBo.getCount() * minAppServiceBo.getIndate());
                                if(DateTimeUtils.match(nowTime,serviceEnd,DateTimeUtils.MATCH_MODEL_GTE)){
                                    getMyServicesRpVo.setPayStatus(Constants.PAY_STATUS_FINISH);
                                }else if(DateTimeUtils.match(nowTime,DateTimeUtils.converLocalDateTimeToDate(getMyServicesRpVo.getNewTime()),DateTimeUtils.MATCH_MODEL_GTE)
                                        && DateTimeUtils.match(nowTime,serviceEnd,DateTimeUtils.MATCH_MODEL_LTE)){
                                    getMyServicesRpVo.setPayStatus(Constants.PAY_STATUS_ING);
                                }
                                getMyServicesRpVo.setServeBeginTimeFont(getMyServicesRpVo.getNewTime());
                                getMyServicesRpVo.setServeEndTimeFont(DateTimeUtils.converDateToLocalDateTime(serviceEnd));
                                getMyServicesRpVoList.add(getMyServicesRpVo);
                            }catch (Exception e){
                                log.info("minAppServiceBo : {}",minAppServiceBo.toString());
                                log.error(e.getMessage(),e);
                            }
                        }
                        userData.put("count",getMyServicesRpVoList.size());
                    }
                }
            }
            return ResultMapHelper.success(getMyServicesRpVoList,userData,ResultMsg.MSG_GET_SUCCESS);
        }else if(myServicesVo.getServiceType() == Constants.MY_SERVICE_TYPE_3){
            return ResultMapHelper.success(getMyServicesRpVoList,userData,ResultMsg.MSG_GET_SUCCESS);
        }
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(DxshAppServiceOrder.BMS_USER_ID,myServicesVo.getUserId());
        queryWrapper.eq(DxshAppServiceOrder.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.eq(DxshAppServiceOrder.ORDER_TYPE, DxshAppServiceOrderService.addedType);
        queryWrapper.orderByAsc(DxshAppServiceOrder.PAY_STATUS);
        queryWrapper.orderByDesc(DxshAppServiceOrder.PAY_TIME);
        Page<DxshAppServiceOrder> page = new Page<>(myServicesVo.getPageNum(),myServicesVo.getPageSize());
        IPage<DxshAppServiceOrder> dxshAppServiceOrderIPage = dxshAppServiceOrderMapper.selectPage(page,queryWrapper);
        userData.putAll(MybatisUtils.UserData(dxshAppServiceOrderIPage));
        List<DxshAppServiceOrder> dxshAppServiceOrderList = dxshAppServiceOrderIPage.getRecords();
        getMyServicesRpVoList.addAll(BeanUtils.copyList(dxshAppServiceOrderList,GetMyServicesRpVo.class));
        Set<Integer> sonSet = new HashSet<>();
        getMyServicesRpVoList.stream().forEach(v->{
            if(v.getServeBeginTime() != null){
                Date beginTime = DateTimeUtils.converStringToDate(v.getServeBeginTime());
                v.setServeBeginTimeFont(DateTimeUtils.converDateToLocalDateTime(beginTime));
            }
            if(v.getServeEndTime() != null){
                Date endTime = DateTimeUtils.converStringToDate(v.getServeEndTime());
                v.setServeEndTimeFont(DateTimeUtils.converDateToLocalDateTime(endTime));
            }
            queryWrapper.clear();
            queryWrapper.eq(DxshAppServices.ID,v.getServiceId());
            DxshAppServices dxshAppServices = dxshAppServicesService.getOne(queryWrapper);
            if(dxshAppServices != null){
                BeanUtils.copyProperties(dxshAppServices,v,"id","newTime");
                sonSet.add(dxshAppServices.getSonId());
            }
        });
        if(sonSet.size() != 0){
            Map<Integer, DxshAppServiceSon> nameByIds = dxshAppServiceSonService.getNameByIds(sonSet);
            for(GetMyServicesRpVo getMyServicesRpVo : getMyServicesRpVoList){
                if(nameByIds.containsKey(getMyServicesRpVo.getSonId())){
                    getMyServicesRpVo.setTypeName(nameByIds.get(getMyServicesRpVo.getSonId()).getSonName());
                }
            }
        }
        return ResultMapHelper.success(getMyServicesRpVoList,userData,ResultMsg.MSG_GET_SUCCESS);
    }

    public Map<String, Object> getRecordList(Integer userId,String storeId) {
        RequestHeaderData requestHeaderData = new RequestHeaderData();
        try{
            String postUrl = AppConfig.getProperty("saas.dxshapp.store.center.service") + "/sys/store/service/getRecordList";
            RpcResponseVo rpcResponseVo = userRestService.getMiniTokenByUserId_v2(userId,requestHeaderData.getString("token"));
            if(rpcResponseVo.isSuccess()){
                String minitoken = rpcResponseVo.getData().toString();
                Map<String, Object> sassHeader = RestTemplateUtils.getSassHeader(minitoken);
                sassHeader.put("storeId", storeId);
                String reponseBody = RestTemplateUtils.postForEntityForJsonByLoadBalanced(postUrl,new HashMap<>(),sassHeader);
                Map<String,Object> resultMap = JSON.parseObject(reponseBody,Map.class);
                return resultMap;
            }
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return ResultMapHelper.failure(ResultMsg.HAND_FAIL);
    }

    @Override
    public List<DxshAppServices> getRecommendService() {
//        Page<DxshAppServices> page = new Page(1,4);
        QueryWrapper<DxshAppServices> queryWrapper = new QueryWrapper();
        queryWrapper.eq(DxshAppServices.IS_DELETE,Constants.COMMON_FLAG_FALSE_INT);
        queryWrapper.eq(DxshAppServices.IS_OFF,Constants.COMMON_FLAG_FALSE_INT);
        List<DxshAppServices> dxshAppServices = dxshAppServicesMapper.selectList(queryWrapper);
        if(dxshAppServices .size() < 4){
            return dxshAppServices;
        }else{
            List<DxshAppServices> dxshAppServicesNew = new ArrayList<>();
            Random random = new Random();
            Set<Integer> randomSet = new HashSet<>();
            while(randomSet.size() < 4){
                int index = random.nextInt(dxshAppServices.size());
                randomSet.add(index);
            }
            for(Integer i : randomSet){
                dxshAppServicesNew.add(dxshAppServices.get(i));
            }
            return dxshAppServicesNew;
        }
    }

    public Map<String,Object> userData(List list, Integer pageNum, Integer pageSize){
        Map<String,Object> userData = new LinkedHashMap<>();
        if(list == null){
            userData.put("count",0);
        }else{
            userData.put("count",list.size());
        }
        userData.put("pageNum",pageNum);
        userData.put("pageSize",pageSize);
        return userData;
    }
}
